﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;

namespace PoolSide
{
    public class ApiInfo
    {
        #region Private Member Variables
        private bool _IsToken;
        private bool _IsUrlHashed;
        private bool _IsApi;
        private string _UrlHistory;
        private string _UrlSell;
        private string _UrlAccount;
        private string _ReturnFormat;
        private string _UrlOrderbook;
        private string _UrlHashMode;
        private string _AuthMode;
        private string _UrlBuy;
        private string _ApiKey;
        private string _Token;
        private string _ApiHowTo;
        private decimal _MinBTCAmount;
        #endregion

        #region Properties
        public bool IsToken
        {
            get { return _IsToken; }
            set { _IsToken = value; }
        }
        public bool IsUrlHashed
        {
            get { return _IsUrlHashed; }
            set { _IsUrlHashed = value; }
        }
        public bool IsApi
        {
            get { return _IsApi; }
            set { _IsApi = value; }
        }
        public string UrlHistory
        {
            get { return _UrlHistory; }
            set { _UrlHistory = value; }
        }
        public string UrlSell
        {
            get { return _UrlSell; }
            set { _UrlSell = value; }
        }
        public string UrlAccount
        {
            get { return _UrlAccount; }
            set { _UrlAccount = value; }
        }
        public decimal MinBTCAmount
        {
            get { return _MinBTCAmount; }
            set { _MinBTCAmount = value; }
        }
        public string ReturnFormat
        {
            get { return _ReturnFormat; }
            set { _ReturnFormat = value; }
        }
        public string UrlOrderbook
        {
            get { return _UrlOrderbook; }
            set { _UrlOrderbook = value; }
        }
        public string UrlHashMode
        {
            get { return _UrlHashMode; }
            set { _UrlHashMode = value; }
        }
        public string AuthMode
        {
            get { return _AuthMode; }
            set { _AuthMode = value; }
        }
        public string UrlBuy
        {
            get { return _UrlBuy; }
            set { _UrlBuy = value; }
        }
        public string ApiKey
        {
            get { return _ApiKey; }
            set { _ApiKey = value; }
        }
        public string Token
        {
            get { return _Token; }
            set { _Token = value; }
        }
        public string ApiHowTo
        {
            get { return _ApiHowTo; }
            set { _ApiHowTo = value; }
        }
        #endregion

        #region Methods

        #endregion

        #region Constructors
        public ApiInfo() { }
        public ApiInfo(string json)
        {
            string val = "";
            using (JsonTextReader jtr = new JsonTextReader(new StringReader(json)))
            {
                while (jtr.Read())
                {
                    if (jtr.TokenType == JsonToken.PropertyName)
                    {
                        switch (jtr.Value.ToString().ToUpper())
                        {
                            case "ISAPI":
                                val = jtr.ReadAsString();
                                _IsApi = val == "1" ? true : false;
                                break;
                            case "ISURLHASHED":
                                val = jtr.ReadAsString();
                                _IsUrlHashed = val == "1" ? true : false;
                                break;
                            case "ISTOKEN":
                                val = jtr.ReadAsString();
                                _IsToken = val == "1" ? true : false;
                                break;
                            case "AUTHMODE": _AuthMode = jtr.ReadAsString(); break;
                            case "URLHASHMODE": _UrlHashMode = jtr.ReadAsString(); break;
                            case "APIKEY": _ApiKey = jtr.ReadAsString(); break;
                            case "URLBUY": _UrlBuy = jtr.ReadAsString(); break;
                            case "URLSELL": _UrlSell = jtr.ReadAsString(); break;
                            case "URLACCOUNT": _UrlAccount = jtr.ReadAsString(); break;
                            case "URLORDERBOOK": _UrlOrderbook = jtr.ReadAsString(); break;
                            case "RETURNFORMAT": _ReturnFormat = jtr.ReadAsString(); break;
                            case "MINIMUMBTC":
                                decimal dec;
                                val = jtr.ReadAsString();
                                if (decimal.TryParse(val, out dec))
                                    _MinBTCAmount = dec;
                                break;
                        }
                    }
                }
            }
        }
        #endregion

    }
}
